package com.zyf.mt.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

//时间戳
public class TimeStamp {
    //生成当前时间的年月日时分秒
    public static String getStamp(){
        //时间
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHssmm");
        return sdf.format(date);
    }
    //日期转字符串
    public static String dateToStr(Date date){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHssmm");
        return sdf.format(date);
    }
    //字符串转日期
    public static Date strToData(String str){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHssmm");
        Date date = null;
        try {
            date = sdf.parse(str);
        } catch (ParseException e) {
            e.printStackTrace();
        } finally {
            return date;
        }
    }
}
